package com.wanyang.controller;

import com.wanyang.service.MemberLikeService;
import com.wanyang.service.PostService;
import com.wanyang.vo.ApiResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(tags="用户点赞相关")
public class MemberLikeController {
    @Autowired
    private MemberLikeService memberLikeService;

    @Autowired
    private PostService postService;

    @ApiOperation(value = "点赞或者取消点赞", notes = "支持的liked_type:POST, POST_COMMENT （帖子，帖子评论）")
    @PostMapping("like/{liked_type}/{id}")
    public ApiResult like(@PathVariable(name = "liked_type") String likedType, @PathVariable Integer id) {
        memberLikeService.likeOrUnlike(likedType, id);
        return ApiResult.success();
    }

    @ApiOperation(value = "收藏帖子或者取消收藏帖子")
    @PostMapping("collect/{postId}")
    public ApiResult collect(@PathVariable Integer postId) {
        postService.collectOrCancel(postId);
        return ApiResult.success();
    }

}
